/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProducirDocGUI.java
 *
 * Created on 13/09/2012, 12:54:54 AM
 */
package Gui;

import ClassControl.CtrProdDocIntE;
import ClassEntidad.Dependencia;
import ClassEntidad.DistribucionDoc;
import ClassEntidad.DocInternoE;
import ClassEntidad.PerExterna;
import ClassEntidad.Persona;
import ClassEntidad.Sistema;
import ClassEntidad.TRD;
import Servicios.DependenciaService;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import util.CparaCombo;

/**
 *
 * @author borisgr04
 */
public class ProducirDocGUI extends javax.swing.JFrame implements  IRecibir {

    CtrProdDocIntE cd; 
    DistribucionDoc rel;

    /** Creates new form ProducirDocGUI */
    public ProducirDocGUI() {
        initComponents();
        inicializar();
    }

    public ProducirDocGUI(DistribucionDoc rel) {
        initComponents();
        inicializar();
         MostrarRel(rel);
    }

   private Dependencia DepActual() {
        DependenciaService ds = new DependenciaService(Sistema.instancia().getEmf());
        CparaCombo dpOr = (CparaCombo) depOrigenC.getSelectedItem();
        Dependencia d = ds.findDependencia(dpOr.getCodigo());
        return d;
    }
   
    private void InicializaTRD() {
        //Llena Comobo Box Serie
        //Inicialziando
        serieC.removeAllItems();
        Dependencia d = DepActual();
        if (!(d == null)) {
            int i = 0;
            for (TRD serie : d.gettRDs()) {
                //if (i > 0) {//ojo la primera serie es la serie Externa
                this.serieC.addItem(new CparaCombo(String.valueOf(serie.getId()), serie.getSerie().toUpperCase()));
                //}
                i++;
                //System.out.print(serie.getSerie());
            }
        }
    }
    
    void inicializar() {
        IniDependencias();

        InicializaTRD();
        
        //OPJO HABILITAR EL MANEJO DE USUARIOS
        //iniFormularios.mostrarUsuarioActual(autorT);
        Habilitar(false);
        IniFecha();
        this.setResizable(false);
        this.setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        nuevoB = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        guardaB = new javax.swing.JButton();
        cancelarB = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        cerrarB = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        depOrigenC = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        serieC = new javax.swing.JComboBox();
        ndocumentoT = new javax.swing.JTextField();
        fechaReg = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        docRelT = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        BuscarPerExt = new javax.swing.JButton();
        destinoC = new javax.swing.JTextField();
        ideDestinoT = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        asuntoT = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        resumenT = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        foliosN = new javax.swing.JSpinner();
        anexosCH = new javax.swing.JCheckBox();
        autorT = new javax.swing.JLabel();

        setTitle("DOCUMENTOS INTERNOS");

        jToolBar1.setRollover(true);

        nuevoB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/New.png"))); // NOI18N
        nuevoB.setText("Nuevo");
        nuevoB.setFocusable(false);
        nuevoB.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nuevoB.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        nuevoB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nuevoBActionPerformed(evt);
            }
        });
        jToolBar1.add(nuevoB);
        jToolBar1.add(jSeparator3);

        guardaB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/save.png"))); // NOI18N
        guardaB.setText("Guardar");
        guardaB.setEnabled(false);
        guardaB.setFocusable(false);
        guardaB.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        guardaB.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        guardaB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardaBActionPerformed(evt);
            }
        });
        jToolBar1.add(guardaB);

        cancelarB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/undo.png"))); // NOI18N
        cancelarB.setText("Cancelar");
        cancelarB.setEnabled(false);
        cancelarB.setFocusable(false);
        cancelarB.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cancelarB.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cancelarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarBActionPerformed(evt);
            }
        });
        jToolBar1.add(cancelarB);
        jToolBar1.add(jSeparator2);

        cerrarB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Log Out_32x32.png"))); // NOI18N
        cerrarB.setText("Cerrar");
        cerrarB.setFocusable(false);
        cerrarB.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cerrarB.setName("cerrarB"); // NOI18N
        cerrarB.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cerrarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cerrarBActionPerformed(evt);
            }
        });
        jToolBar1.add(cerrarB);

        jLabel12.setText("Dependencia Origen");

        depOrigenC.setEnabled(false);
        depOrigenC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                depOrigenCActionPerformed(evt);
            }
        });

        jLabel13.setText("Serie Documental");

        jLabel5.setText("Destino");

        serieC.setEnabled(false);

        ndocumentoT.setEditable(false);

        fechaReg.setEditable(false);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Correspondencia Interna", "Correspondencia Externa" }));
        jComboBox1.setEnabled(false);

        jLabel2.setText("Tipo Correspondencia");

        jLabel1.setText("Fecha y Hora");

        jLabel4.setText("N° Documento");

        docRelT.setEnabled(false);

        jLabel8.setText("N° Documento Rel");

        BuscarPerExt.setText("...");
        BuscarPerExt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BuscarPerExtActionPerformed(evt);
            }
        });

        destinoC.setEditable(false);

        ideDestinoT.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(serieC, 0, 319, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(depOrigenC, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(ideDestinoT)
                            .addComponent(destinoC))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BuscarPerExt, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(16, 16, 16)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ndocumentoT, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                            .addComponent(fechaReg, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                            .addComponent(jComboBox1, 0, 154, Short.MAX_VALUE))
                        .addGap(30, 30, 30))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(docRelT, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(depOrigenC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(serieC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(fechaReg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4)
                    .addComponent(ndocumentoT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BuscarPerExt)
                    .addComponent(destinoC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(docRelT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(ideDestinoT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jLabel6.setText("Asunto");

        asuntoT.setEnabled(false);

        jLabel7.setText("Resumen");

        resumenT.setColumns(20);
        resumenT.setRows(5);
        resumenT.setEnabled(false);
        jScrollPane1.setViewportView(resumenT);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(asuntoT)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel6))
                            .addComponent(asuntoT, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(jLabel7)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel9.setText("Autor");

        jLabel11.setText("No de Folios");

        foliosN.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        foliosN.setEnabled(false);

        anexosCH.setText("Anexos");
        anexosCH.setEnabled(false);

        autorT.setText("usuarioActual");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addGap(29, 29, 29)
                .addComponent(autorT, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(foliosN, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(anexosCH)
                .addContainerGap(123, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(foliosN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(anexosCH)
                    .addComponent(autorT))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 738, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cerrarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cerrarBActionPerformed
        // TODO add your handling code here:
        //this.setVisible(true);
        BandejaEntGUI fui = new BandejaEntGUI();
        fui.setVisible(true);
    }//GEN-LAST:event_cerrarBActionPerformed

    private void Guardar() {
        try {
            DocInternoE d = new DocInternoE();
            CparaCombo serie = (CparaCombo) serieC.getSelectedItem();
            
            if (serie == null) {
                JOptionPane.showMessageDialog(this, "Seleccione Serie", Sistema.instancia().getNomApp(), JOptionPane.WARNING_MESSAGE);
                return;
            }

            CparaCombo depOrg = (CparaCombo) depOrigenC.getSelectedItem();
            if (depOrg == null) {
                JOptionPane.showMessageDialog(this, "Seleccione Dependencia Origen", Sistema.instancia().getNomApp(), JOptionPane.WARNING_MESSAGE);
                return;
            }

            //Funcionario f = new Funcionario();
            //d.setAnexos(anexosCH.ch/);
            
            d.setAsunto(asuntoT.getText());
            d.setResumen(resumenT.getText());
            
            d.setAnexos(anexosCH.isSelected());
            d.setFolios(Integer.parseInt(this.foliosN.getValue().toString()));
            d.setDocOriginador(rel);
            cd.setIdSerie(Long.valueOf(serie.getCodigo()));
            cd.setIdeDepOrigen(depOrg.getCodigo());
            cd.setIdeProductor(Sistema.instancia().getUsuAct().getNroIde());//Enviar Usuario Actual
            cd.setIdeDestino(this.ideDestinoT.getText());
            cd.setDoc(d);
            
            cd.Guardar();

            if (cd.isValido()) {
                this.ndocumentoT.setText(String.valueOf(cd.getDoc().getNoDocumento()));
                this.fechaReg.setText(d.getFechaReg().toString());
                JOptionPane.showMessageDialog(this, cd.getMensaje(), Sistema.instancia().getNomApp(), JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, cd.getMensaje(), Sistema.instancia().getNomApp(), JOptionPane.WARNING_MESSAGE);
                 this.Limpiar("");
            this.Habilitar(false);
            }

        } catch (Exception e) {
           JOptionPane.showMessageDialog(this, e.getMessage(), Sistema.instancia().getNomApp(), JOptionPane.ERROR_MESSAGE);
       }
    }
    private void guardaBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardaBActionPerformed
        // TODO add your handling code here:
        int r = JOptionPane.showConfirmDialog(this, "Desea Guardar y Enviar el Documento", Sistema.instancia().getNomApp(), JOptionPane.YES_NO_OPTION);

        System.out.print(r);
        if (r == JOptionPane.YES_OPTION) {
            Guardar();
        } else {
            System.out.print("No quizo guardar");
        }


    }//GEN-LAST:event_guardaBActionPerformed

    private void Habilitar(boolean val) {
        asuntoT.setEnabled(val);
        resumenT.setEnabled(val);
        anexosCH.setEnabled(val);
        foliosN.setEnabled(val);
        destinoC.setEnabled(false);
        ideDestinoT.setEnabled(false);
        
        this.depOrigenC.setEnabled(val);
        this.serieC.setEnabled(val);
        this.destinoC.setEnabled(val);
        this.guardaB.setEnabled(val);
        this.cancelarB.setEnabled(val);
    }

    private void Limpiar(String val) {
        asuntoT.setText(val);
        resumenT.setText(val);
        anexosCH.setSelected(false);
        foliosN.setValue(0);
        destinoC.setText("");
        IniFecha();
        
        //this.depOrigenC.setSelectedIndex(-1);
        this.serieC.setSelectedIndex(-1);
        
    }
       private void MostrarRel(DistribucionDoc rel) {
        this.rel=rel;
        this.docRelT.setText(String.valueOf(rel.getDocumento().getNoDocumento()));
        this.asuntoT.setText("Resp:>>"+rel.getDocumento().getAsunto());
        this.resumenT.setText("Escriba la Respuesta\\n\\n"+rel.getDocumento().getResumen());
        
        this.Habilitar(true);
        
    }

    private void nuevoBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevoBActionPerformed
        // TODO add your handling code here:
        cd= new CtrProdDocIntE(Sistema.instancia().getEmf());
        this.Habilitar(true);
        this.Limpiar("");
    }//GEN-LAST:event_nuevoBActionPerformed

    private void cancelarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarBActionPerformed
        // TODO add your handling code here:
        this.Habilitar(false);
        this.Limpiar("");
    }//GEN-LAST:event_cancelarBActionPerformed

    private void depOrigenCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_depOrigenCActionPerformed
        // TODO add your handling code here:
        this.InicializaTRD();
    }//GEN-LAST:event_depOrigenCActionPerformed

    private void BuscarPerExtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BuscarPerExtActionPerformed
        // TODO add your handling code here:
        BuscarPerExtGUI guiPerExt = new BuscarPerExtGUI(this);
        guiPerExt.setVisible(true);
    }//GEN-LAST:event_BuscarPerExtActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ProducirDocGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BuscarPerExt;
    private javax.swing.JCheckBox anexosCH;
    private javax.swing.JTextField asuntoT;
    private javax.swing.JLabel autorT;
    private javax.swing.JButton cancelarB;
    private javax.swing.JButton cerrarB;
    private javax.swing.JComboBox depOrigenC;
    private javax.swing.JTextField destinoC;
    private javax.swing.JTextField docRelT;
    private javax.swing.JTextField fechaReg;
    private javax.swing.JSpinner foliosN;
    private javax.swing.JButton guardaB;
    private javax.swing.JTextField ideDestinoT;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTextField ndocumentoT;
    private javax.swing.JButton nuevoB;
    private javax.swing.JTextArea resumenT;
    private javax.swing.JComboBox serieC;
    // End of variables declaration//GEN-END:variables

    private void IniDependencias() {
        //Llena Comobo Box Dependencia
        List<Dependencia> lstDep=Sistema.instancia().getDependencias();
        for (Dependencia d :lstDep ) {
            this.depOrigenC.addItem(new CparaCombo(d.getId(), d.getNombre()));
        }
    }

  

     @Override
    public void Recibir(Persona o) {
       PerExterna per = (PerExterna) o;
       CparaCombo cc= new CparaCombo(per.getNroIde(), per.getNombres().toUpperCase());
       this.destinoC.setText(per.getNombres()+" "+per.getApellidos());
       this.ideDestinoT.setText(per.getNroIde());

    }

    private void IniFecha() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");;
        this.fechaReg.setText(sdf.format(date));
    }
}
